package jsd2302.src.io;

import java.io.*;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws IOException {
       /*
        //文件流：将字节写入到文件中
        FileOutputStream fos=new FileOutputStream("pw.txt");
        OutputStreamWriter osw=new OutputStreamWriter(fos);
        BufferedWriter bw=new BufferedWriter(osw);
        //自动刷新，构造器第一个参数为流，第2个参数可以传入boolean类型的数据来表示是否打开自动刷新功能
        PrintWriter pw=new PrintWriter(bw,true);
        Scanner scan=new Scanner(System.in);
        System.out.println("请开始输入内容");
        while(true){
            String line=scan.nextLine();
            if("exit".equals(line)){
                break;
            }
        pw.println(line);
           // pw.flush();//冲水一把,不然会一直等到数据输入完毕才会存入到文件中

        }
        pw.close();

        */
       FileOutputStream fos=new FileOutputStream("pw.txt");
       OutputStreamWriter osw=new OutputStreamWriter(fos);
       BufferedWriter bw=new BufferedWriter(osw);

       PrintWriter pw=new PrintWriter(bw,true );
       Scanner scan=new Scanner(System.in);
        System.out.println("请输入内容");
        while(true){
            String line=scan.nextLine();
            if("exit".equals(line)){
                break;

            }
            pw.println(line);
        }
        pw.close();
    }
}
